﻿using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.CommandWpf;
using KINLO.UI.Main.View;
using KINLO.UI.Main.Services;
using GalaSoft.MvvmLight.Messaging;
using System.Windows;
using System.Collections.ObjectModel;
using KINLO.Model;
using KINLO.Data.Reporitory;
using System.Windows.Controls;
using KINLO.UI.Main.Hepler;
using KINLO.Model.Dto;
using System.IO;
using Microsoft.Win32;
using System.Net.Sockets;
using System.Threading;
using KINLO.UI.Main.MES;
using KINLO.Model.InfoModel;
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
using System.ComponentModel;

namespace KINLO.UI.Main.VM
{
    public class MainVM : ViewModelBase
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(MainVM));
        MainWindow View;
        K20021002CoreService CorService;
        System.Timers.Timer timer = new System.Timers.Timer(10000);
        WeightReporitory DB = new WeightReporitory();
        WeightBakReporitory BDB = new WeightBakReporitory();
        LogReporitory LDB = new LogReporitory();

        //待机停机原因
        public ObservableCollection<ComboxItem> Standbys { get; set; }

        public ObservableCollection<NavigationItem> NavigationItems { get; } = new ObservableCollection<NavigationItem>();

        int standbySelectedValue;
        public int StandbySelectedValue
        {
            get { return standbySelectedValue; }
            set
            {
                standbySelectedValue = value;
                RaisePropertyChanged(() => StandbySelectedValue);
            }
        }
        bool isPressureChart;
        public bool IsPressureChart
        {
            get { return isPressureChart; }
            set
            {
                isPressureChart = value;
                RaisePropertyChanged(() => IsPressureChart);
            }
        }

        public object PressureChart { get; set; }

        public Counter Count { get; set; }
        public MainVM(MainWindow view)
        {

            View = view;

            NavigationItems.Add(new NavigationItem { ID = 0, Header = "生产统计接口(小时)", Tag = "Kinlo.GUI.ViewModel.CountDayViewModel", Content = new CountHourView() });
            NavigationItems.Add(new NavigationItem { ID = 1, Header = "生产统计接口(天)", Tag = "Kinlo.GUI.ViewModel.CountHourViewModel", Content = new CountDayView() });
            NavigationItems.Add(new NavigationItem { ID = 1, Header = "设备履历接口", Tag = "Kinlo.GUI.ViewModel.EquipmentStatuViewModel", Content = new EquipmentStatuView() });

            PressureChart = new PressureChartView();
            IsPressureChart = false;

            //return;
            //Standbys = new ObservableCollection<ComboxItem>
            //{
            //    new ComboxItem { Name = "正常运行", Value = 1 },
            //    new ComboxItem { Name = "环境异常", Value = 2 },
            //    new ComboxItem { Name = "清洁点检", Value = 3 },
            //    new ComboxItem { Name = "交接班", Value = 4 },
            //    new ComboxItem { Name = "等待物料", Value = 5 },
            //    new ComboxItem { Name = "来料异常", Value = 6 },
            //    new ComboxItem { Name = "品质异常", Value = 7 },
            //    new ComboxItem { Name = "物料切换", Value = 8 },
            //    new ComboxItem { Name = "维护保养", Value = 9 },
            //    new ComboxItem { Name = "设备异常", Value = 10 },
            //    new ComboxItem { Name = "技术鉴定", Value = 11 }
            //};
            //standbySelectedValue = 1;

            Init();


        }
        void Init()
        {
          

            Count = Counter.Load();
        
            this.View.listEvtInfo.Background = this.View.datagrid2.Background;
            EventInfos = new ObservableCollection<string>();
            Messenger.Default.Register<string>(this, "ReceiveEventInfo", new Action<string>((s) => {
                this.View.Dispatcher.BeginInvoke(new Action(() =>
                {
                    var msg = DateTime.Now.ToString("HH:mm:ss") + " " + s;
                    EventInfos.Add(msg);
                    this.View.listEvtInfo.ScrollIntoView(msg);
                }));
            }));
            Messenger.Default.Register<bool>(this, "InjectionStatus", new Action<bool>((s) =>
            {
                InjectionStatus = s;
            }));

            Messenger.Default.Register<string>(this, "NotUnqualified", new Action<string>((s) => {
                this.View.Dispatcher.BeginInvoke(new Action(() => {
                    MessageBox.Show(s, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                }));
            }));
            //Messenger.Default.Register<Weight>(this, "UpdateFBattryInfoToUI", new Action<Weight>((w) => {
            //    this.View.Dispatcher.BeginInvoke(new Action(() => {
            //        var ww = FrontWeights.Where(s => s.ID == w.ID).FirstOrDefault();
            //        if (ww != null)
            //            FrontWeights.Remove(ww);
            //        FrontWeights.Add(w);q
            //        var frontWeights = FrontWeights.OrderByDescending(s => s.ProductDate);
            //        FrontWeights = new ObservableCollection<Weight>(frontWeights);
            //    }));
            //}));
            Messenger.Default.Register<Weight>(this, "UpdateBBattryInfoToUI", new Action<Weight>((w) => {
                this.View.Dispatcher.BeginInvoke(new Action(() => {
                    var ww = BackWeights.Where(s => s.ID == w.ID).FirstOrDefault();
                    if (ww != null)
                        BackWeights.Remove(ww);
                    BackWeights.Add(w);
                    var backweights = BackWeights.OrderByDescending(s => s.ProductDate);
                    BackWeights = new ObservableCollection<Weight>(backweights);
                    TrayCount = BackWeights.Count;
                    QualifiedCount = BackWeights.Where(s => s.IsGoods >= 100).Count();
                    UnQualifiedCount = BackWeights.Where(s => s.IsGoods < 100).Count();
                    if (trayCount != 0 && QualifiedCount != 0)
                        QualifiedCountRate = (Decimal.Parse(QualifiedCount.ToString()) / TrayCount).ToString("P2");
                }));
            }));

            ProductBatch = GlobalValues.Line;
            WeightRef = GlobalValues.WeightRef1;
            //WaveRange = GlobalValues.WeightWave1;
            WaveRange = GlobalValues.WeightRef1 - GlobalValues.WeightWave1Min;

            BackWeights = new ObservableCollection<Weight>();
            Task.Run(() => {
                try
                {
                    CorService = new K20021002CoreService(GlobalValues.Line, Count);
                }catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
              
                //CorService.Count = Count;
                Thread.Sleep(1000);
                CorService.InjectionMachine.Start();
            });


            UITitle = GlobalValues.UITitle;
            var a1 = GlobalValues.RecordSaveDays;
            try
            {
                DB.DeleteWeightRecordByDays((int)GlobalValues.RecordSaveDays);
                EBWeightTest(GlobalValues.FrontElecBalances);
                EBWeightTest(GlobalValues.BackElecBalances);
            }
            catch (Exception ex)
            {
                MessageBox.Show("88888888" + ex.Message);
            }
 
          
     
            timer.Elapsed += Timer_Elapsed;
            timer.Enabled = true;
            QualifiedStatus = "%";
            NotLimitDate = false;
            StartTime = DateTime.Now.AddDays(-1);
            EndTime = DateTime.Now;
            InfoDataModel.Tmp.Load();
            Timer_Elapsed(null, null);
        }
        object ResutlLocker = new object();
        string TesstResult = "";
        void EBWeightTest(List<Machine> ebs)
        {
            if (ebs != null && ebs.Count > 0)
            {
                foreach (var eb in ebs)
                {
                    Task.Run(() => Test(eb));
                }
            }
        }
        void Test(Machine m)
        {
            try
            {
                var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                s.Connect(m.IP, m.Port);
                s.ReceiveTimeout = 500;
                s.SendTimeout = 500;
                var readByte = new byte[4096];
                var len = s.Receive(readByte);
                if (len > 0)
                { }
                else
                {
                    lock (ResutlLocker)
                    {
                        TesstResult += string.Format("电子称{0}:{1}连接失败\r\n", m.IP, m.Port);
                        Messenger.Default.Send(string.Format("电子称{0}:{1}连接失败\r\n", m.IP, m.Port), "ReceiveEventInfo");
                    }
                }
            }
            catch (Exception ex)
            {
                lock (ResutlLocker)
                {
                    TesstResult += string.Format("电子称{0}:{1}连接失败\r\n", m.IP, m.Port);
                    Messenger.Default.Send(string.Format("电子称{0}:{1}连接失败\r\n", m.IP, m.Port), "ReceiveEventInfo");
                }
            }
        }

        string uITitle;
        public string UITitle
        {
            get { return uITitle; }
            set
            {
                uITitle = value;
                RaisePropertyChanged("UITitle");
            }
        }
        bool inectionStatus;
        public bool InjectionStatus
        {
            get { return inectionStatus; }
            set
            {
                inectionStatus = value;
                RaisePropertyChanged("InjectionStatus");
            }
        }

        bool serviceIsStarted;
        public bool ServiceIsStarted
        {
            get { return serviceIsStarted; }
            set
            {
                serviceIsStarted = value;
                RaisePropertyChanged("ServiceIsStarted");
            }
        }


        #region Menu 

        RelayCommand cmdStandbysSelectionChanged;
        public RelayCommand CmdStandbysSelectionChanged
        {
            get { return cmdStandbysSelectionChanged ?? (cmdStandbysSelectionChanged = new RelayCommand(() => DoCmdStandbysSelectionChanged())); }
        }

        RelayCommand cmdHistoryEvent;
        public RelayCommand CmdHistoryEvent
        {
            get { return cmdHistoryEvent ?? (cmdHistoryEvent = new RelayCommand(() => DoCmdHistoryEvent())); }
        }
        void DoCmdHistoryEvent()
        {
            var win = new HistoryEventView();
            win.ShowDialog();
        }
        void DoCmdStandbysSelectionChanged()
        {
            string standbyName = Standbys.FirstOrDefault(item => int.Parse(item.Value.ToString()) == standbySelectedValue)?.Name;
            int standbyNumber = standbySelectedValue;
            InfoDataModel.Tmp.standbyName = standbyName;
            InfoDataModel.Tmp.standbyNumber = standbyNumber;
            InfoDataModel.Tmp.Save();
        }

        RelayCommand cmdCommunicationTest;
        public RelayCommand CmdCommunicationTest
        {
            get { return cmdCommunicationTest ?? (cmdCommunicationTest = new RelayCommand(() => DoCmdCommunicationTest())); }
        }
        void DoCmdCommunicationTest()
        {
            var result = MessageBox.Show("通信测试将会终止当前称重记录，是否继续", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {
                Messenger.Default.Send(true, "StopInjectionMachineSvc");
                var win = new CommunicationTestView();
                win.ShowDialog();
                Messenger.Default.Send(false, "StopInjectionMachineSvc");
            }
        }

        RelayCommand cmdFrontWeightClear;
        public RelayCommand CmdFrontWeightClear
        {
            get { return cmdFrontWeightClear ?? (cmdFrontWeightClear = new RelayCommand(() => DoCmdFrontWeightCleart())); }
        }
        void DoCmdFrontWeightCleart()
        {
            if ((new PassConfirmView()).ShowDialog() == true)
            {
                var win = new FrontWeightClearView();
                win.ShowDialog();
            }
        }
        //MesInfoView
        RelayCommand cmdMesInfoView;
        public RelayCommand CmdMesInfoView
        {
            get { return cmdMesInfoView ?? (cmdMesInfoView = new RelayCommand(() => DoCmdMesInfoView())); }
        }
        void DoCmdMesInfoView()
        {
            if ((new MesInfoView()).ShowDialog() == true)
            {
                var win = new MesInfoView();
                win.ShowDialog();
            }
        }
        //CmdEquipmentMaintain
        RelayCommand cmdEquipmentMaintain;
        public RelayCommand CmdEquipmentMaintain
        {
            get { return cmdEquipmentMaintain ?? (cmdEquipmentMaintain = new RelayCommand(() => DoCmdEquipmentMaintain())); }
        }
        void DoCmdEquipmentMaintain()
        {
            if (InfoDataModel.Tmp.EnbleMesOnOff)
            {
                var result = InjectMes.MESEquipmentMaintain();
                if (result == 1)
                {
                    MessageBox.Show("设备报修成功");
                }
                else
                {
                    MessageBox.Show("设备报修失败！！！");
                }
                //CorService.MESEquipmentMaintain(); 
            }
            else
            {
                MessageBox.Show($"MES未打开，请先打开MES开关!");
            }
        }


        RelayCommand cmdExportToMes;
        public RelayCommand CmdExportToMes
        {
            get { return cmdExportToMes ?? (cmdExportToMes = new RelayCommand(() => DoCmdExportToMes())); }
        }
        void DoCmdExportToMes()
        {
            var win = new ExportToMesView();
            win.ShowDialog();
        }

        #endregion

        #region 主页
        //扫码数
        int scanCount;
        public int ScanCount
        {
            get { return scanCount; }
            set
            {
                scanCount = value;
                RaisePropertyChanged("ScanCount");
            }
        }
        //称重数
        int weightCount;
        public int WeightCount
        {
            get { return weightCount; }
            set
            {
                weightCount = value;
                RaisePropertyChanged("WeightCount");
            }
        }
        //托架数
        int trayCount;
        public int TrayCount
        {
            get { return trayCount; }
            set
            {
                trayCount = value;
                RaisePropertyChanged("TrayCount");
            }
        }
        //合格数
        int qualifiedCount;
        public int QualifiedCount
        {
            get { return qualifiedCount; }
            set
            {
                qualifiedCount = value;
                RaisePropertyChanged("QualifiedCount");
            }
        }
        //不合格数
        int unQualifiedCount;
        public int UnQualifiedCount
        {
            get { return unQualifiedCount; }
            set
            {
                unQualifiedCount = value;
                RaisePropertyChanged("UnQualifiedCount");
            }
        }
        //合格率
        string qualifiedCountRate;
        public string QualifiedCountRate
        {
            get { return qualifiedCountRate; }
            set
            {
                qualifiedCountRate = value;
                RaisePropertyChanged("QualifiedCountRate");
            }
        }

        //重量参考值
        Decimal? weightRef;
        public Decimal? WeightRef
        {
            get { return weightRef; }
            set
            {
                weightRef = value;
                RaisePropertyChanged("WeightRef");
            }
        }

        //波动范围
        Decimal? waveRange;
        public Decimal? WaveRange
        {
            get { return waveRange; }
            set
            {
                waveRange = value;
                RaisePropertyChanged("WaveRange");
            }
        }

        //生产批号
        string productBatch;
        public string ProductBatch
        {
            get { return productBatch; }
            set
            {
                productBatch = value;
                RaisePropertyChanged("ProductBatch");
            }
        }
        ObservableCollection<string> eventInfos;
        public ObservableCollection<string> EventInfos
        {
            get { return eventInfos; }
            set
            {
                eventInfos = value;
                RaisePropertyChanged("EventInfos");
            }
        }

        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (!string.IsNullOrEmpty(TesstResult))
            {
                var msg = TesstResult;
                TesstResult = "";
                MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            var fWeight = DB.GetBattryInfoByFrontSegment();

            if (fWeight != null && fWeight.Count > 0)
            {
                ScanCount = fWeight.Count;
                WeightCount = fWeight.Where(s => (!string.IsNullOrEmpty(s.FWeightTime.ToString())) == true).Count();
            }
            else
            {
                ScanCount = 0;
                WeightCount = 0;
            }
            var ffWeight = DB.GetBattryInfoByStage();
            if (ffWeight != null)
                FrontWeights = new ObservableCollection<Weight>(ffWeight);
            //if (bWeight != null)
            //    BackWeights = new ObservableCollection<Weight>(bWeight);
        }
        ObservableCollection<Weight> frontWeights;
        public ObservableCollection<Weight> FrontWeights
        {
            get { return frontWeights; }
            set
            {
                frontWeights = value;
                RaisePropertyChanged("FrontWeights");
            }
        }

        ObservableCollection<Weight> backWeights;
        public ObservableCollection<Weight> BackWeights
        {
            get { return backWeights; }
            set
            {
                backWeights = value;
                RaisePropertyChanged("BackWeights");
            }
        }
        RelayCommand cmdAbout;
        public RelayCommand CmdAbout
        {
            get { return cmdAbout ?? (cmdAbout = new RelayCommand(() => DoCmdAbout())); }
        }
        void DoCmdAbout()
        {
            var win = new AboutView();
            win.ShowDialog();
        }

        RelayCommand cmdStopService;
        public RelayCommand CmdStopService
        {
            get { return cmdStopService ?? (cmdStopService = new RelayCommand(() => DoCmdStopService())); }
        }
        void DoCmdStopService()
        {
            CorService.InjectionMachine.Stop();
        }

        RelayCommand cmdModityPass;
        public RelayCommand CmdModityPass
        {
            get { return cmdModityPass ?? (cmdModityPass = new RelayCommand(() => DoCmdModityPass())); }
        }
        void DoCmdModityPass()
        {
            if ((new PassConfirmView()).ShowDialog() == true)
            {
                var win = new ModifyPass();
                win.ShowDialog();
            }
        }

        RelayCommand cmdExit;
        public RelayCommand CmdExit
        {
            get { return cmdExit ?? (cmdExit = new RelayCommand(() => DoCmdExit())); }
        }
        void DoCmdExit()
        {
            if (MessageBox.Show("在机器生产过程中不要退出,确认退出?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                Messenger.Default.Unregister(this);
                this.View.Close();
            }
        }

        RelayCommand cmdCounterClearZero;
        public RelayCommand CmdCounterClearZero
        {
            get { return cmdCounterClearZero ?? (cmdCounterClearZero = new RelayCommand(() => DoCmdCounterClearZero())); }
        }
        void DoCmdCounterClearZero()
        {
            if (MessageBox.Show("确定要清零", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                Messenger.Default.Send("手动清零", "CloseCount");
                //Count.ClearZero();
            }
        }

        RelayCommand cmdParamSetting;
        public RelayCommand CmdParamSetting
        {
            get { return cmdParamSetting ?? (cmdParamSetting = new RelayCommand(() => DoCmdParamSetting())); }
        }
        void DoCmdParamSetting()
        {
            if ((new PassConfirmView()).ShowDialog() == true)
            {
                var win = new SettingView();
                win.ShowDialog();
            }
        }
        RelayCommand<DataGridRowEventArgs> cmdLoadingRow;
        public RelayCommand<DataGridRowEventArgs> CmdLoadingRow
        {
            get { return cmdLoadingRow ?? (cmdLoadingRow = new RelayCommand<DataGridRowEventArgs>((e) => DoCmdLoadingRow(e))); }
        }
        void DoCmdLoadingRow(DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }


        //关闭按钮
        //RelayCommand<System.ComponentModel.CancelEventArgs> cmdWindow_Closing;
        //public RelayCommand<System.ComponentModel.CancelEventArgs> CmdWindow_Closing
        //{
        //    get { return cmdWindow_Closing ?? (cmdWindow_Closing = new RelayCommand<System.ComponentModel.CancelEventArgs>((e) => DoCmdWindow_Closing(e))); }
        //}
        //RelayCommand cmdWindow_Closing;
        //public RelayCommand CmdWindow_Closing
        //{
        //    get { return cmdWindow_Closing ?? (cmdWindow_Closing = new RelayCommand(() => DoCmdWindow_Closing())); }
        //}

        //void DoCmdWindow_Closing()
        //{
        //    if (!(MessageBoxResult.OK == MessageBox.Show("确认关闭系统", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information)))
        //    {
        //        //e.Cancel = true;
        //    }
        //}
        #endregion

        #region 数据查询

        //开始时间
        DateTime startTime;
        public DateTime StartTime
        {
            get { return startTime; }
            set
            {
                startTime = value;
                RaisePropertyChanged("StartTime");
            }
        }
        //结束时间
        DateTime endTime;
        public DateTime EndTime
        {
            get { return endTime; }
            set
            {
                endTime = value;
                RaisePropertyChanged("EndTime");
            }
        }

        //生产批号
        string prdBatch;
        public string PrdBatch
        {
            get { return prdBatch; }
            set
            {
                prdBatch = value;
                RaisePropertyChanged("PrdBatch");
            }
        }

        //编号
        string number;
        public string Number
        {
            get { return number; }
            set
            {
                number = value;
                RaisePropertyChanged("Number");
            }
        }

        //合格状态
        string qualifiedStatus;
        public string QualifiedStatus
        {
            get { return qualifiedStatus; }
            set
            {
                qualifiedStatus = value;
                RaisePropertyChanged("QualifiedStatus");
            }
        }

        /// <summary>
        /// 不限时间
        /// </summary>
        bool notLimitDate;
        public bool NotLimitDate
        {
            get { return notLimitDate; }
            set
            {
                notLimitDate = value;
                RaisePropertyChanged("NotLimitDate");
            }
        }
        ObservableCollection<WeightDto> queryResultWeight;
        public ObservableCollection<WeightDto> QueryResultWeight
        {
            get { return queryResultWeight; }
            set
            {
                queryResultWeight = value;
                RaisePropertyChanged("QueryResultWeight");
            }
        }
        RelayCommand cmdQuery;
        public RelayCommand CmdQuery
        {
            get { return cmdQuery ?? (cmdQuery = new RelayCommand(() => DoCmdQuery())); }
        }

        void DoCmdQuery()
        {
            var batch = string.IsNullOrEmpty(PrdBatch) ? "%" : "%" + PrdBatch + "%";
            var numb = string.IsNullOrEmpty(Number) ? "%" : "%" + Number + "%";
            string isGoods = "";
            if (QualifiedStatus == "%")
                isGoods = "1,2,3,4,5,6,7,8,9,10,100";
            else if (QualifiedStatus == "True")
                isGoods = "100";
            else if (QualifiedStatus == "False")
                isGoods = "1,2,3,4,5,6,7,8,9,10";

            var weights = BDB.GetBattryInfo(StartTime, EndTime, NotLimitDate, batch, numb, isGoods);
            if (weights != null)
            {
                QueryResultWeight = new ObservableCollection<WeightDto>(weights);
            }
        }

        //导出
        RelayCommand cmdExport;
        public RelayCommand CmdExport
        {
            get { return cmdExport ?? (cmdExport = new RelayCommand(() => DoCmdExport())); }
        }

        void DoCmdExport()
        {
            try
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter = "Excel 工作簿(*.xls)|*.xls";
                if (dlg.ShowDialog() == true)
                {
                    var result = ExcelHelper.SaveToExcel(dlg.FileName, QueryResultWeight);
                    if (result)
                    {
                        MessageBox.Show("保存成功");
                    }

                }

            }
            catch (IOException ioex)
            {
                MessageBox.Show(ioex.Message);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }

        /// <summary>
        /// 启动加压杠曲线图实施加载
        /// </summary>
        RelayCommand pressureChart_Start;
        public RelayCommand PressureChart_Start
        {
            get {
                     return pressureChart_Start ?? (pressureChart_Start = new RelayCommand(() =>
                    {
                        if(CorService!=null)
                        {
                            CorService.PressureChart_Start();
                        }
                        
                    }));
                }
        }
        /// <summary>
        /// 关闭加压杠曲线图实施加载
        /// </summary>
        RelayCommand pressureChart_Close;
        public RelayCommand PressureChart_Close
        {
            get
            {
                return pressureChart_Close ?? (pressureChart_Close = new RelayCommand(() =>
                {
                    if (CorService != null)
                    {
                        CorService.PressureChart_Close();
                    }

                }));
            }
        }



        //CmdMesUpload
        RelayCommand cmdMesUpload;
        public RelayCommand CmdMesUpload
        {
            get { return cmdMesUpload ?? (cmdMesUpload = new RelayCommand(() => DoCmdMesUpload())); }
        }

        void DoCmdMesUpload()
        {
            //QueryResultWeight
            for (int i = 0; i < QueryResultWeight.Count; i++)
            {
                var batt = QueryResultWeight[i];
                var result = InjectMes.MESProductUpLoad(batt,Count);
            }
        }
        #endregion
    }


    public class NavigationItem
    {
        public int ID { get; set; }
        public string Header { get; set; }
        public string Tag { get; set; }
        public object Content { get; set; }
    }
}
